<?php
namespace Admin\Model;
use Think\Model;
use Think\Model\RelationModel;
class UsedModel extends RelationModel{
    //自动完成
    protected $_auto = array(
        array('add_time', 'time', 1, 'function'),

    );
    //自动验证
    protected $_validate = array(
        array('title', 'require', '请填写房源名称'),
        array('average_price','number','价格必须是数字'),
        array('total_price','number','楼盘总价必须为数字')
    );
    //关联关系
    protected $_link = array(
        'Estate'=>array(
            'mapping_type'=>self::BELONGS_TO,
            'foreign_key'=>'estate_id',
            'mapping_fields'=>'title',	//要取出的字段
            'as_fields'=>'title:estateTitle'	//使用别名
        )
    );
    //获取相关房源
    public function get_houses ($map, $star, $end){
        $field = 'u.*,d.build,d.fool,d.room';
        $table = array ('yk_used'=>'u','yk_dict'=>'d');
        return $this->field($field)->table($table)->where ($map)
                  ->limit ($star, $end)
                  ->select ();

    }

}